﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Iservices;
using Microsoft.AspNetCore.Mvc;
using Model;
namespace Hr.Controllers
{
    /// <summary>
    ///  公共字段设置，包括薪酬设置，职称设置，国籍，民族，宗教信仰，政治面貌，教育年限，学历,专业，特长，爱好，培训项目，培训成绩，奖励项目，奖励等级
    /// </summary>
    public class SataryController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        private readonly Iconfig_public_charServices d;

        public SataryController(Iconfig_public_charServices d)
        {

            this.d = d;
        }

        public async Task<IActionResult> public_char()
        {
            //需求：获取数据，显示在页面
            List<config_public_char> dt = await d.Select();
            ViewData.Model = dt;
            return View();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ActionResult> Del(int id)
        {
            int dt = await d.Del(id);
            if (dt > 0)
            {
                return Content("<script>alert('删除成功');window.location.href='/Satary/public_char'</script>", "text/html", Encoding.Default);

            }
            else
            {
                return Content("<script>alert('删除失败');window.location.href='/Satary/public_char'</script>");
            }

        }

        [HttpGet]
        public IActionResult public_char_add()
        {
            return View();
        }
        /// <summary>
        /// /添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> public_char_add(config_public_char t)
        {
            if (ModelState.IsValid)
            {
                //需求：做新增操作
                int result = await d.Add(t);
                if (result > 0)
                {

                    return Content("<script>alert('添加成功');window.location.href='/Satary/public_char'</script>", "text/html", Encoding.Default);
                }
                else
                {
                    return View(t);
                }
            }
            else
            {
                return View(t);
            }
        }
    }
}
